public partial class Program
{
    static void UnionTest()
    {
        MyUnion union = new MyUnion();

        // 设置整数值
        union.IntValue = 42;
        Console.WriteLine($"IntValue: {union.IntValue}");
        Console.WriteLine($"FloatValue: {union.FloatValue}");
        Console.WriteLine($"CharValue: {union.CharValue}");

        // 设置浮点值
        union.FloatValue = 3.14f;
        Console.WriteLine($"IntValue: {union.IntValue}");
        Console.WriteLine($"FloatValue: {union.FloatValue}");
        Console.WriteLine($"CharValue: {union.CharValue}");

    }
}
[StructLayout(LayoutKind.Explicit)]
struct MyUnion
{
    [FieldOffset(0)]
    public int IntValue;

    [FieldOffset(0)]
    public float FloatValue;

    [FieldOffset(0)]
    public char CharValue;
}
